package com.model;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "ACESSO")
/*@NamedQueries({
    @NamedQuery(name="Acesso.findAll",
                query="SELECT p FROM Acesso p"),
    @NamedQuery(name = "User.findAcessoByUser", query = "select p from Acesso p where p.user = :user")
})*/ 
public class Acesso implements Serializable {
	
	private static final long serialVersionUID = 1L;

	/*public static final String FIND_BY_USER = "Acesso.findAcessoByUser";
	public static final String FIND_ALL = "Acesso.findAll";*/

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;

	@Column(unique = true)
	private String acesso;
	
	@OneToMany
	@JoinTable(name = "sistema_acesso", joinColumns = { @JoinColumn(name = "acessoId", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "sistemaId", referencedColumnName = "id") })
	private List<Sistema> sistemas;
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getAcesso() {
		return acesso;
	}

	public void setAcesso(String acesso) {
		this.acesso = acesso;
	}

	public List<Sistema> getSistemas() {
		return sistemas;
	}

	public void setSistemas(List<Sistema> sistemas) {
		this.sistemas = sistemas;
	}

	@Override
	public int hashCode() {
		return getId();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Acesso) {
			Acesso acesso = (Acesso) obj;
			return acesso.getId() == id;
		}
		return false;
	}
}